﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Runtime.Serialization;
using Newtonsoft.Json;
using Newtonsoft.Json.Converters;
using MobileSales.Model.Util;

namespace MobileSales.Model.Params
{
    public enum FieldType
    {
        Boolean,
        Integer,
        Double,
        DateTime,
        String,
        Dictionary
    }

    public static class FieldTypes
    {

        #region Private members
        private static FieldType[] _fieldTypes = new FieldType[] { FieldType.Boolean,
                                                                   FieldType.Integer,
                                                                   FieldType.Double,
                                                                   FieldType.DateTime,
                                                                   FieldType.Dictionary,
                                                                   FieldType.String };
        private static string[] _fieldQualifiedNames = new string[] { "System.Boolean",
                                                                       "System.Int32",
                                                                       "System.Double",
                                                                       "System.DateTime",
                                                                       "MobileSales.Model.Params.DictionaryParam",
                                                                       "System.String" }; 
        #endregion

        #region GetQualifiedName
        public static string GetQualifiedName(FieldType type)
        {
            for (int i = 0; i < _fieldTypes.Length; i++)
            {
                if (_fieldTypes[i] == type)
                {
                    return _fieldQualifiedNames[i];
                }
            }
            return "System.String";
        }
        #endregion

        #region GetFieldType
        public static FieldType GetFieldType(string qualifiedName)
        {
            for (int i = 0; i < _fieldTypes.Length; i++)
            {
                if (_fieldQualifiedNames[i] == qualifiedName)
                {
                    return _fieldTypes[i];
                }
            }
            return FieldType.String;
        }
        #endregion
    }
}
